package com.starchen.optimalselection.product.controller;

import com.starchen.optimalselection.common.model.QueryParamsForm;
import com.starchen.optimalselection.common.model.ResultPage;
import com.starchen.optimalselection.common.utils.Result;
import com.starchen.optimalselection.common.valid.AddGroup;
import com.starchen.optimalselection.common.valid.UpdateGroup;
import com.starchen.optimalselection.common.service.BrandService;
import com.starchen.optimalselection.common.model.Brand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 品牌 管理
 *
 * @author daxilong
 * @email daxilong@gmail.com
 * @date 2022-08-14 19:57:36
 */
@Api(tags = "品牌管理")
@RestController
@RequestMapping("admin/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @ApiOperation("分页查询品牌")
    @RequestMapping("/page")
    public Result list(QueryParamsForm brandQueryVo){
        ResultPage page = brandService.queryPage(brandQueryVo);
        return Result.success(page);
    }

    @ApiOperation("查询所有品牌")
    @RequestMapping("/all")
    public Result all(){
        List<Brand> page = brandService.list();
        return Result.success(page);
    }

    @ApiOperation("根据ID查询品牌")
    @GetMapping("/info/{brandId}")
    public Result info(@PathVariable("brandId") Long brandId){
		Brand brand = brandService.getById(brandId);
        return Result.success(brand);
    }

    @ApiOperation("新建品牌")
    @PostMapping("/create")
    public Result save(@Validated({AddGroup.class}) @RequestBody Brand brand){
		brandService.save(brand);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation("修改品牌")
    @PostMapping("/update")
    public Result update(@Validated({UpdateGroup.class}) @RequestBody Brand brand){
        brandService.updateById(brand);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation("删除品牌")
    @PostMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
		brandService.removeByIds(Arrays.asList(ids));
        return Result.success();
    }

}
